package com.java88.springboot04.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java88.springboot04.entity.Emp;
import com.java88.springboot04.mapper.EmpMapper;
import com.java88.springboot04.service.EmpService;
import org.springframework.stereotype.Service;

@Service
public class EmpServiceImpl implements EmpService {
	private EmpMapper empMapper;

	public EmpServiceImpl(EmpMapper empMapper) {
		this.empMapper = empMapper;
	}

	@Override
	public PageInfo<Emp> findAll(Integer deptno, int pageNum, int pageSize) {
		Page<Emp> page = PageHelper.startPage(pageNum, pageSize);
		if(deptno == null)
			empMapper.findAll();
		else
			empMapper.findByDeptno(deptno);

		return new PageInfo<>(page);
	}

	@Override
	public Emp findByEmpno(int empno) {
		return empMapper.findByEmpno(empno);
	}

	@Override
	public int save(Emp emp) {
		return empMapper.save(emp);
	}

	@Override
	public int update(Emp emp) {
		return empMapper.update(emp);
	}

	@Override
	public int delete(int empno) {
		return empMapper.delete(empno);
	}
}
